<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
use think\Db;
use app\admin\model\Fin_account;//会计科目
use app\admin\model\Fin_co2buy;//收款登记
use app\admin\model\Journal;//日记账
use app\admin\model\Sale;//销售订单
use app\admin\model\Sale_invoice;//发票订单
use app\admin\model\Sale_pay_bill;//银行单
use app\admin\model\Sale_pay_cheque;//支票单
use app\admin\model\Sale_pack;//装箱单


class Finance extends Auth
{
    //会计科目列表
    public function finaccount(Request $request)
    {
        $res = $request->param();
        $res['lang'] = $this->lang;
        $finaccount = new Fin_account();
        if ($request->isAjax() && $request->isPost() && isset($res['getfinaccount'])) {
            $finaccounts = $finaccount->getfinaccount($res);
            $getfinaccount = array_slice($finaccounts['data'], ($res['page'] - 1) * $res['pageSize'], $res['pageSize']);
            echo json_encode(array('getfinaccount' => $getfinaccount, 'size' => $finaccounts['count']));
        } elseif ($request->isAjax() && $request->isPost() && isset($res['finaccounts'])) {
            //获取这个国家下的所有科目名称
            $data = $finaccount->finaccounts($res);
            echo json_encode($data);
        } elseif ($request->isGet()) {
            return view('finaccount/finaccount');
        }
    }

    //会计的添加
    public function finaccountadd(Request $request)
    {
        $data = $request->param();
        $finaccount = new Fin_account();
        if ($request->isPost() && $request->isAjax()) {
            $finaccountret = $finaccount->finaccountaddedit($data);
            $udata["status"] = $finaccountret['status'];
            $udata['msg'] = $finaccountret['msg'];
            echo json_encode($udata);
        }
    }

    //会计的编辑
    public function finaccountedit(Request $request)
    {
        $data = $request->param();
        $finaccount = new Fin_account();
        if ($request->isPost() && $request->isAjax() && isset($data['getfinaccount'])) {
            //编辑的请求接口
            echo json_encode(getinfo($data['id'], 'fin_account'));
        } elseif ($request->isAjax() && $request->isPost() && isset($data['act'])) {
            $finaccountret = $finaccount->finaccountaddedit($data);
            $udata["status"] = $finaccountret['status'];
            $udata['msg'] = $finaccountret['msg'];
            echo json_encode($udata);

        }
    }

    //会计科目的删除
    public function finaccountdel(Request $request)
    {
        $data = $request->param();
        $finaccount = new Fin_account();
        if ($request->isPost() && $request->isAjax()) {
            $finaccountret = $finaccount->finaccountdel($data);
            $udata["status"] = $finaccountret['status'];
            $udata['msg'] = $finaccountret['msg'];
            echo json_encode($udata);
        }
    }

    //会计科目设置权限
    public function setfinaccroot(Request $request)
    {
        $data = $request->param();
        $data['lang'] = $this->lang;
        $finaccount = new Fin_account();
        if ($request->isGet()) {
            return view('finaccount/setaccroot', [
                'id' => $data['id'],
                'str' => 'setfinaccroot'
            ]);
        } elseif ($request->isPost() && $request->isAjax() && isset($data['getroot'])) {
            $admin_postion_id = session('admin')['position_id'];
            $country_id = '';
            $mapfinaccount['id'] = array('in',implode(',',getpostion('fin_account', $data['id'])));//当前会计的上一级id
            $name = implode('/', array_column(getables('fin_account',$mapfinaccount,'name'), 'name'));
            if ($admin_postion_id != 1 && $admin_postion_id != 2) {
                $country_id =getValue('position',['id'=>$admin_postion_id],'country_id');
            }
            $info = getinfo($data['id'], 'fin_account');
            echo json_encode(array('name' => $name, 'lang' => $data['lang'], 'info' => $info, 'country_id' => $country_id));
        } elseif ($request->isAjax() && $request->isPost() && $data['act'] == 'setaccroot') {
            $finaccountret = $finaccount->setaccroot($data);
            $udata["status"] = $finaccountret['status'];
            $udata['msg'] = $finaccountret['msg'];
            echo json_encode($udata);
        }
    }

    //日记账
    public function journal(Request $request)
    {
        $res = $request->param();
        $res['lang'] = $this->lang;
        $finaccount = new Fin_account();
        if ($request->isAjax() && $request->isPost() && isset($res['getjournal'])) {
            $journal = new Journal();
            $journals = $journal->getjournal($res);
            echo json_encode(array(
                'getjournals' => $journals['data'],
                'size' => $journals['count'],
                'moneys' => $journals['moneys'],
                'dateday' => $journals['dateday'],//日期
                'finaccounts' => $journals['finaccounts']//记账科目
            ));
        } elseif ($request->isAjax() && $request->isPost() && isset($res['finaccounts'])) {
            //获取的是不同国家的记账科目（管理员）
            $datares = $finaccount->finaccounts($res);
            echo json_encode($datares);
        } elseif ($request->isGet()) {
            return view('journal/journal');
        }
    }

    //处理日记账中的月年账单详情权限
    public function journalmonthyear(Request $request)
    {
        $data = $request->param();
        //科目名称
        $finaccountins =implode(',',getpostion('fin_account', $data['account_id']));//记账科目的上级id
        $mapname['id']=array('in',$finaccountins);
        $name = implode('/', array_column(getables('fin_account',$mapname,'name'), 'name'));//记账科目名称
        //判断是否是不调整的收入
        $infofin = getinfo($data['account_id'], 'fin_account');
        //权限条件
        $admin = session('admin');
        $admin_authids = explode(",", $admin['auth_ids']);//权限
        $country_poid = getValue('position',['id'=>$admin['position_id']],'country_id');//国家id
        $posid = array_column(getFrames('position', null, $country_poid), 'id');
        $mapadmin['position_id']=array('in',implode(',',$posid));
        $adminids = array_column(getables('admin',$mapadmin,'id'), 'id');//获取能查看的员工的ids
        //时间条件
        $yearmonth = explode('-', date('Y-m-d', $data['happen_day']));
        $mapyearwhere['year'] = $mapmonthwhere['year'] = $yearmonth[0];//年
        $mapmonthwhere['month'] = $yearmonth[1];//月
        //科目条件
        $mapyearwhere['account_id'] = $mapmonthwhere['account_id'] = $data['account_id'];

        if ($infofin['adjust'] == 1) {
            //收入
            $color = 'blue';
            $sign = '+';
        } elseif ($infofin['adjust'] == 2) {
            //支出
            $color = 'red';
            $sign = '-';
        } else {
            //不调整
            $color = 'gray';
            $sign = '';
        }
        //年月账单查看限制条件
         if ($admin['position_id'] != 1 && $admin['position_id'] != 2) {
                if (in_array('177', $admin_authids) && !in_array('178', $admin_authids)) {
                    //查看自己下级的员工
                    $mapmonthwhere['create_id'] = ['in', $adminids];
                    //查看自己和自己下级员工的年账单
                    $mapyearwhere['create_id'] = ['in', $adminids];
                } elseif (in_array('176', $admin_authids) && !in_array('177', $admin_authids) && !in_array('178', $admin_authids)) {
                    //只能看自己的账单
                    $mapmonthwhere['create_id'] = $admin['id'];
                     //只能看自己的年账单
                    $mapyearwhere['create_id'] = $admin['id'];
                } elseif(!in_array('176', $admin_authids) && !in_array('177', $admin_authids) && !in_array('178', $admin_authids)) {
                    //默认看自己的月账单
                    $mapmonthwhere['create_id'] = $admin['id'];
                    //默认看自己的年账单
                    $mapyearwhere['create_id'] = $admin['id'];
                }
            }
        if ($request->isGet() && isset($data['month'])) {
            //月份查看
            $datajountry = Db::name('journal')->where($mapmonthwhere)->select();
            $date=getTimeDate($data['happen_day'],'10');
            $newview = 'journal/monthdeta';
        } elseif ($request->isGet() && isset($data['year'])) {
            //一年中这个科目的所有收支情况
            $datajountry = Db::name('journal')->field('sum(amount) as amount,account_id,happen_day')->where($mapyearwhere)->group('month')->select();
            $date=getTimeDate($data['happen_day'],'1');
            $newview = 'journal/yeardeta';
        }
        foreach ($datajountry as $datajountrykey => $datajountryval) {
                $datajountry[$datajountrykey]['happen_year'] = getTimeDate($datajountryval['happen_day'], 10);
                $datajountry[$datajountrykey]['happen_month'] = getTimeDate($datajountryval['happen_day'], 7);
        }
        //合计，无论是收入，还是支出，不调整的合计
        $moneys = array_sum(array_column($datajountry, 'amount'));
        return view($newview, [
            'name' => $name,
            'date' => $date,
            'data' => $datajountry,
            'summoney' => $moneys,
            'color' => $color,
            'sign' => $sign
        ]);
    }

    //日记账的编辑权限判断
    public function journaledit(Request $request)
    {
        $data = $request->param();
        $admin = session('admin');
        $admin_authids = explode(",", $admin['auth_ids']);
        $info =getinfo($data['id'],'journal','id,happen_day,account_id,amount,remarks');
        $info['country_id'] =getValue('fin_account',['id'=>$info['account_id']],'country_id');
        $info['happen_date'] = getTimeDate($info['happen_day'], 7);
        if ($admin['position_id'] != 1 && $admin['position_id'] != 2) {
            if (in_array('171', $admin_authids)) {
                //拥有所有权限
                $udata["status"] = 1;
                $udata['msg'] = $info;
                echo json_encode($udata);
            } elseif (in_array('170', $admin_authids) && !in_array('171', $admin_authids)) {
                //拥有7天权限
                $time = (time() - $info['happen_day']) / 86400;
                if (ceil($time) > 7) {
                    $udata["status"] = 3;
                    $udata['msg'] = lang("no_permission,_please_contact_administrator");
                    echo json_encode($udata);
                } else {
                    $udata["status"] = 1;
                    $udata['msg'] = $info;
                    echo json_encode($udata);
                }
            } elseif (in_array('169', $admin_authids) && !in_array('170', $admin_authids) && !in_array('171', $admin_authids)) {
                //拥有3天权限
                $time = (time() - $info['happen_day']) / 86400;
                if (ceil($time) > 3) {
                    $udata["status"] = 3;
                    $udata['msg'] = lang("no_permission,_please_contact_administrator");
                    echo json_encode($udata);
                } else {
                    $udata["status"] = 1;
                    $udata['msg'] = $info;
                    echo json_encode($udata);
                }
            } elseif (in_array('168', $admin_authids) && !in_array('169', $admin_authids) && !in_array('170', $admin_authids) && !in_array('171', $admin_authids)) {
                //拥有当天的权限
                $time = (time() - $info['happen_day']) / 86400;
                if (ceil($time) > 1) {
                    $udata["status"] = 3;
                    $udata['msg'] = lang("no_permission,_please_contact_administrator");
                    echo json_encode($udata);
                } else {
                    $udata["status"] = 1;
                    $udata['msg'] = $info;
                    echo json_encode($udata);
                }
            } else {
                //没有权限
                $udata["status"] = 3;
                $udata['msg'] = lang("no_permission,_please_contact_administrator");
                echo json_encode($udata);
            }
        } else {
            $udata["status"] = 1;
            $udata['msg'] = $info;
            echo json_encode($udata);
        }
    }

    //日记账单的的删除权限
    public function journaldel(Request $request)
    {
        $data = $request->param();
        $admin = session('admin');
        $admin_authids = explode(",", $admin['auth_ids']);
        $info = Db::name('journal')->field('happen_day')->where('id', $data['id'])->find();
        //判断权限
        if ($request->isPost() && $request->isAjax()) {
            $journal = new Journal();
            if ($admin['position_id'] != 1 && $admin['position_id'] != 2) {
                //拥有所有权限
                if (in_array('175', $admin_authids)) {
                    $journalret = $journal->journaldel($data);
                    $udata["status"] = $journalret['status'];
                    $udata['msg'] = $journalret['msg'];
                    echo json_encode($udata);
                } elseif (in_array('174', $admin_authids) && !in_array('175', $admin_authids)) {
                    //拥有7天权限
                    $time = (time() - $info['happen_day']) / 86400;
                    if (ceil($time) > 7) {
                        $udata["status"] = 3;
                        $udata['msg'] = lang("no_permission,_please_contact_administrator");
                        echo json_encode($udata);
                    } else {
                        $journalret = $journal->journaldel($data);
                        $udata["status"] = $journalret['status'];
                        $udata['msg'] = $journalret['msg'];
                        echo json_encode($udata);
                    }
                } elseif (in_array('173', $admin_authids) && !in_array('174', $admin_authids) && !in_array('175', $admin_authids)) {
                    //拥有3天权限
                    $time = (time() - $info['happen_day']) / 86400;
                    if (ceil($time) > 3) {
                        $udata["status"] = 3;
                        $udata['msg'] = lang("no_permission,_please_contact_administrator");
                        echo json_encode($udata);
                    } else {
                        $journalret = $journal->journaldel($data);
                        $udata["status"] = $journalret['status'];
                        $udata['msg'] = $journalret['msg'];
                        echo json_encode($udata);
                    }
                } elseif (in_array('172', $admin_authids) && !in_array('173', $admin_authids) && !in_array('174', $admin_authids) && !in_array('175', $admin_authids)) {
                    //拥有当天的权限
                    $time = (time() - $info['happen_day']) / 86400;
                    if (ceil($time) > 1) {
                        $udata["status"] = 3;
                        $udata['msg'] = lang("no_permission,_please_contact_administrator");
                        echo json_encode($udata);
                    } else {
                        $journalret = $journal->journaldel($data);
                        $udata["status"] = $journalret['status'];
                        $udata['msg'] = $journalret['msg'];
                        echo json_encode($udata);
                    }
                } else {
                    //没有权限
                    $udata["status"] = 3;
                    $udata['msg'] = lang("no_permission,_please_contact_administrator");
                    echo json_encode($udata);
                }
            } else {
                $journalret = $journal->journaldel($data);
                $udata["status"] = $journalret['status'];
                $udata['msg'] = $journalret['msg'];
                echo json_encode($udata);
            }
        }
    }
    //采购收支
    public function cotwobuy(Request $request)
    {
        $res = $request->param();
        $res['lang'] = $this->lang;
        $fin_co2buy = new Fin_co2buy();
        if ($request->isPost() && $request->isAjax() && isset($res['cotwobuy'])) {
            $fin_co2buys = $fin_co2buy->getfin_co2buys($res);
            echo json_encode($fin_co2buys);
        } elseif ($request->isPost() && $request->isAjax() && isset($res['getcompanyname'])) {
            //获取公司名称
            echo json_encode(array_slice(model('Company')->getcompanyname($res), 0, 10));
        } else if ($request->isPost() && $request->isAjax() && isset($res['getcompanyacc'])) {
            //获取公司的账号
            $co_bank = new \app\admin\model\Co_bank();
            $banks = $co_bank->getBanks($res);
            echo json_encode($banks);
        } else {
            return view('finaccount/cotwobuy');
        }
    }

    //付款登记的编辑
    public function cotwobuyedit(Request $request)
    {
        $data = $request->param();
        $fin_co2buy = new Fin_co2buy();
        if ($request->isAjax() && $request->isPost() && isset($data['getcotwobuyedit'])) {
            //编辑获取的接口
            $data['lang'] = $this->lang;
            $info = $fin_co2buy->cotwobuyedit($data);
            echo json_encode($info);
        } elseif ($request->isAjax() && $request->isPost() && $data['act'] == 'cotwobuyedit') {
            //编辑提交的接口
            $cotwobuyret = $fin_co2buy->cotwobuyaddedit($data);
            $udata["status"] = $cotwobuyret['status'];
            $udata['msg'] = $cotwobuyret['msg'];
            echo json_encode($udata);

        }
    }

    //付款登记的添加
    public function cotwobuyadd(Request $request)
    {
        $data = $request->param();
        $fin_co2buy = new Fin_co2buy();
        if ($request->isAjax() && $request->isPost() && $data['act'] == 'cotwobuyadd') {
            //添加提交的接口
            $cotwobuyret = $fin_co2buy->cotwobuyaddedit($data);
            $udata["status"] = $cotwobuyret['status'];
            $udata['msg'] = $cotwobuyret['msg'];
            echo json_encode($udata);
        }
    }

    //付款登记的的详情的点击
    public function cotwobuydetails(Request $request)
    {
        $res = $request->param();
        $res['lang'] = $this->lang;
        $fin_co2buy = new Fin_co2buy();
        if ($request->isGet()) {
            return view('finaccount/cotwodetails',[
                'htid'=>$res['id']
            ]);
        }else if($request->isPost() && $request->isAjax() && isset($res['getdata'])){
            $datares = $fin_co2buy->cotwobuydetail($res);
            echo json_encode($datares);
        }
    }

    //付款登记的删除
    public function cotwobuydel(Request $request)
    {
        $data = $request->param();
        $fin_co2buy = new Fin_co2buy();
        $admin = session('admin');
        $admin_authids = explode(",", $admin['auth_ids']);
        $happen_day = getValue('fin_co2buy',['id'=>$data['id']],'happen_day');
        if ($request->isPost() && $request->isAjax()) {
            if ($admin['position_id'] != 1 && $admin['position_id'] != 2) {
                //拥有所有权限
                if (in_array('400', $admin_authids)) {
                    $cotwobuyret = $fin_co2buy->cotwobuydel($data);
                    $udata["status"] = $cotwobuyret['status'];
                    $udata['msg'] = $cotwobuyret['msg'];
                    echo json_encode($udata);
                } elseif (in_array('398', $admin_authids) && !in_array('400', $admin_authids)) {
                    //拥有7天权限
                    $time = (time() - $happen_day) / 86400;
                    if (ceil($time) > 7) {
                        $udata["status"] = 3;
                        $udata['msg'] = lang("no_permission,_please_contact_administrator");
                        echo json_encode($udata);
                    } else {
                        $cotwobuyret = $fin_co2buy->cotwobuydel($data);
                        $udata["status"] = $cotwobuyret['status'];
                        $udata['msg'] = $cotwobuyret['msg'];
                        echo json_encode($udata);
                    }
                }elseif (in_array('187', $admin_authids) && !in_array('398', $admin_authids) && !in_array('400', $admin_authids)) {
                    //拥有当天的权限
                    $time = (time() - $happen_day) / 86400;
                    if (ceil($time) > 1) {
                        $udata["status"] = 3;
                        $udata['msg'] = lang("no_permission,_please_contact_administrator");
                        echo json_encode($udata);
                    } else {
                        $cotwobuyret = $fin_co2buy->cotwobuydel($data);
                        $udata["status"] = $cotwobuyret['status'];
                        $udata['msg'] = $cotwobuyret['msg'];
                        echo json_encode($udata);
                    }
                } else {
                    //没有权限
                    $udata["status"] = 3;
                    $udata['msg'] = lang("no_permission,_please_contact_administrator");
                    echo json_encode($udata);
                }
            } else {
                $cotwobuyret = $fin_co2buy->cotwobuydel($data);
                $udata["status"] = $cotwobuyret['status'];
                $udata['msg'] = $cotwobuyret['msg'];
                echo json_encode($udata);
            }
        }
    }

    //处理销售财务页面
    public function sales(Request $request)
    {
        $Sale = new Sale();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isGet()) {
            return view('salesfinancial/list2accountant');
        } elseif ($request->isAjax() && $request->isPost() && isset($res['getdata'])) {
            //列表渲染数据
            $data = $Sale->getsalepay($res);
            echo json_encode($data);
        } elseif ($request->isAjax() && $request->isPost() && isset($res['noaccount'])) {
            //确认款已经收到和 确认金额没有到账点击
            $data = $Sale->onyesaccount($res);
            echo json_encode($data);
        }
    }

    //处理销售财务页面 已收到点击 1
    public function receiptyes(Request $request)
    {
        $Sale = new Sale();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isAjax() && $request->isPost()) {
            $data = $Sale->getsalepaycode($res);
            echo json_encode($data);
        }
    }

    //处理销售财务页面 未收到点击 2
    public function receiptno(Request $request)
    {
        $Sale = new Sale();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isAjax() && $request->isPost()) {
            $data = $Sale->getsalepaycode($res);
            echo json_encode($data);
        }
    }

    //处理销售财务页面 查看点击 3
    public function receiptcheck(Request $request)
    {
        $Sale = new Sale();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isAjax() && $request->isPost()) {
            $data = $Sale->getsalepaycode($res);
            echo json_encode($data);
        }
    }

    //处理销售财务页面 恢复点击（坏账中的恢复）
    public function resumeaccount(Request $request)
    {
        $Sale = new Sale();
        $admin=session('admin');
        $admin_authids = explode(",", $admin['auth_ids']);//用户的权限
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isAjax() && $request->isPost()) {
            $payreginfo=getinfo($res['id'],'sale_payreg');
            //坏账中的恢复判断是否有权限
            if ($admin['position_id'] != 1 && $admin['position_id'] != 2) {
                //拥有所有权限
                if (in_array('402', $admin_authids)) {
                    $data = $Sale->huisale($res,$payreginfo);
                    echo json_encode($data);
                } elseif (in_array('252', $admin_authids) && !in_array('402', $admin_authids)) {
                    //拥有24小时权限
                    $time = (time() - $payreginfo['fail_at']) / 86400;
                    if (ceil($time) > 1) {
                        $udata["status"] = 3;
                        $udata['msg'] = lang("no_permission,_please_contact_administrator");
                        echo json_encode($udata);
                    } else {
                        $data = $Sale->huisale($res,$payreginfo);
                        echo json_encode($data);
                    }
                } else {
                    //没有权限
                    $udata["status"] = 3;
                    $udata['msg'] = lang("no_permission,_please_contact_administrator");
                    echo json_encode($udata);
                }
            } else {
                $data = $Sale->huisale($res,$payreginfo);
                echo json_encode($data);
            }
        }
    }

    //处理销售财务页面 取消收账点击（已完成）
    public function cancelaccount(Request $request)
    {
        $Sale = new Sale();
        $res = $request->param();
        $admin=session('admin');
        $admin_authids = explode(",", $admin['auth_ids']);//用户的权限
        $res['lang'] = $this->lang;
        if ($request->isAjax() && $request->isPost()) {
            $salepayreginfo = getinfo($res['id'], 'sale_payreg');
            //判断取消收账是否有权限
            if ($admin['position_id'] != 1 && $admin['position_id'] != 2) {
                //拥有所有权限
                if (in_array('401', $admin_authids)) {
                    $data = $Sale->quxiaosale($res, 1);
                    echo json_encode($data);
                } elseif (in_array('253', $admin_authids) && !in_array('401', $admin_authids)) {
                    //拥有8小时权限
                    if($salepayreginfo['fail_at']>0){
                        $time=$salepayreginfo['fail_at'];
                    }else{
                        $time=$salepayreginfo['success_at'];
                    }
                    $timecha = time() - $time;
                    if ($timecha > 28800) {
                        $udata["status"] = 3;
                        $udata['msg'] = lang("no_permission,_please_contact_administrator");
                        echo json_encode($udata);
                    } else {
                        $data = $Sale->quxiaosale($res, 1);
                        echo json_encode($data);
                    }
                } else {
                    //没有权限
                    $udata["status"] = 3;
                    $udata['msg'] = lang("no_permission,_please_contact_administrator");
                    echo json_encode($udata);
                }
            } else {
                $data = $Sale->quxiaosale($res, 1);
                echo json_encode($data);
            }
        }
    }

    //处理销售财务页面中 收到按钮
    public function receiveaccount(Request $request)
    {
        $Sale = new Sale();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isAjax() && $request->isPost()) {
            $data = $Sale->receivesale($res);
            echo json_encode($data);
        }
    }

    //处理销售财务页面中 取消按钮
    public function removeaccount(Request $request)
    {
        $Sale = new Sale();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isAjax() && $request->isPost()) {
            $data = $Sale->quxiaosale($res, 2);
            echo json_encode($data);
        }
    }

    //处理开票员的页面
    public function saleinvoice(Request $request)
    {
        $Sale_invoice = new Sale_invoice();
        $res = $request->param();
        if ($request->isGet()) {
            return view('salesfinancial/list2drawer_invoice',['isshow'=>1]);
        } elseif ($request->isPost() && $request->isAjax() && isset($res['getdata'])) {
            $data = $Sale_invoice->getsaleinvoice($res);
            echo json_encode($data);
        }
    }

    //开票员中的 开发票点击 查看 编辑
    public function codeinvoice(Request $request)
    {
        $Sale_invoice = new Sale_invoice();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isAjax() && $request->isPost() && isset($res['code'])) {
            $data = $Sale_invoice->codeinvoice($res);
            echo json_encode($data);
        } elseif ($request->isAjax() && $request->isPost() && isset($res['leftdata'])) {
            //开发票的保存点击
            $data = $Sale_invoice->savedatainvoice($res);
            echo json_encode($data);
        }
    }

    //已完成中的删除
    public function invoicedelone(Request $request)
    {
        $Sale_invoice = new Sale_invoice();
        $res = $request->param();
        if ($request->isAjax() && $request->isPost()) {
            $data = $Sale_invoice->delresumeinvoice($res, 1);
            echo json_encode($data);
        }
    }

    //已取消中的删除
    public function invoicedeltwo(Request $request)
    {
        $Sale_invoice = new Sale_invoice();
        $res = $request->param();
        if ($request->isAjax() && $request->isPost()) {
            $data = $Sale_invoice->delresumeinvoice($res, 2);
            echo json_encode($data);
        }
    }

    //已删除中的恢复
    public function resume(Request $request)
    {
        $Sale_invoice = new Sale_invoice();
        $res = $request->param();
        if ($request->isAjax() && $request->isPost()) {
            $data = $Sale_invoice->delresumeinvoice($res, 3);
            echo json_encode($data);
        }
    }


    //处理销售中银行单
    public function drawerbill(Request $request)
    {
        $Sale_bill = new Sale_pay_bill();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isGet()) {
            return view('salesfinancial/list2drawer_bill',['isshow'=>1]);
        } elseif ($request->isAjax() && $request->isPost() && isset($res['getdata'])) {
            //银行单数据的获取
            $data = $Sale_bill->getsalebill($res);
            echo json_encode($data);
        } elseif ($request->isPost() && $request->isAjax() && isset($res['savebtn'])) {
            //对数据的写入
            $data = $Sale_bill->savebill($res);
            echo json_encode($data);
        }
    }

    //银行单的银行单查看（待开票）
    public function bankbill(Request $request)
    {
        $Sale_bill = new Sale_pay_bill();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isPost() && $request->isAjax()) {
            //点击银行单获取的数据
            $data = $Sale_bill->getbankbill($res);
            echo json_encode($data);
        }
    }

    //银行单已完成中的编辑
    public function editbill(Request $request)
    {
        $Sale_bill = new Sale_pay_bill();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isPost() && $request->isAjax()) {
            //点击银行单获取的数据
            $data = $Sale_bill->getbankbill($res);
            echo json_encode($data);
        }
    }

    //银行单已完成中的删除
    public function delbill(Request $request)
    {
        $Sale_bill = new Sale_pay_bill();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isPost() && $request->isAjax()) {
            //删除银行单
            $data = $Sale_bill->delbill($res);
            echo json_encode($data);
        }
    }

    //支票管理页面
    public function list2cheque(Request $request)
    {
        $Sale_pay_cheque = new Sale_pay_cheque();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isGet()) {
            return view('salesfinancial/list2cheque');
        } elseif ($request->isAjax() && $request->isPost() && isset($res['getdata'])) {
            //支票表数据的获取
            $data = $Sale_pay_cheque->getsalecheque($res);
            echo json_encode($data);
        } elseif ($request->isPost() && $request->isAjax() && isset($res['savebtn'])) {
            //对数据的写入
            $data = $Sale_pay_cheque->savecheque($res);
            echo json_encode($data);
        }
    }

    //支票管理已存入中的取消
    public function chequequxiao(Request $request)
    {
        $Sale_pay_cheque = new Sale_pay_cheque();
        $res = $request->param();
        if ($request->isAjax() && $request->isPost()) {
            $data = $Sale_pay_cheque->chequequxiao($res, 1);
            echo json_encode($data);
        }
    }

    //支票管理中已使用的取消
    public function chequequxiaos(Request $request)
    {
        $Sale_pay_cheque = new Sale_pay_cheque();
        $res = $request->param();
        if ($request->isAjax() && $request->isPost()) {
            $data = $Sale_pay_cheque->chequequxiao($res, 2);
            echo json_encode($data);
        }
    }

    //支票管理页面中已使用的确认
    public function chequequeren(Request $request)
    {
        $Sale_pay_cheque = new Sale_pay_cheque();
        $res = $request->param();
        if ($request->isAjax() && $request->isPost()) {
            $data = $Sale_pay_cheque->chequequeren($res, 1);
            echo json_encode($data);
        }
    }

    //支票管理页面中已使用的退票
    public function chequequerens(Request $request)
    {
        $Sale_pay_cheque = new Sale_pay_cheque();
        $res = $request->param();
        if ($request->isAjax() && $request->isPost()) {
            $data = $Sale_pay_cheque->chequequeren($res, 2);
            echo json_encode($data);
        }
    }

    //支票管理中存入账户
    public function accountcheque(Request $request)
    {
        $Sale_pay_cheque = new Sale_pay_cheque();
        $res = $request->param();
        if ($request->isAjax() && $request->isPost()) {
            $data = $Sale_pay_cheque->accountcheque($res, 1);
            echo json_encode($data);
        }
    }

    //支票管理中的使用
    public function usecheque(Request $request)
    {
        $Sale_pay_cheque = new Sale_pay_cheque();
        $res = $request->param();
        if ($request->isAjax() && $request->isPost()) {
            $data = $Sale_pay_cheque->accountcheque($res, 2);
            echo json_encode($data);
        }
    }

    //销售中的装箱单
    public function enchaseboxer(Request $request)
    {
        $Sale_pack = new Sale_pack();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isGet()) {
            return view('salesfinancial/list2boxer',['isshow'=>1]);
        } elseif ($request->isAjax() && $request->isPost() && isset($res['getdata'])) {
            //支票表数据的获取
            $data = $Sale_pack->getsalepack($res);
            echo json_encode($data);
        }
    }

    //销售中装箱的编辑
    public function boxerboxing(Request $request)
    {
        $Sale_pack = new Sale_pack();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isGet()) {
            return view('salesfinancial/list2boxer_boxing');
        } else if ($request->isAjax() && $request->isPost() && isset($res['getdata'])) {
            $data = $Sale_pack->getsaleboxing($res);
            echo json_encode($data);
        } else if ($request->isPost() && $request->isAjax() && isset($res['savebtn'])) {
            $data = $Sale_pack->addeditsaleboxing($res);
            echo json_encode($data);
        }
    }

    //装箱单的查看
    public function enchasechakan(Request $request)
    {
        $Sale_pack = new Sale_pack();
        $res = $request->param();
        $res['lang'] = $this->lang;
        if ($request->isAjax() && $request->isPost() && isset($res['chakan'])) {
            //支票表数据的获取
            $data = $Sale_pack->detailpack($res);
            echo json_encode($data);
        }
    }
}

